{{-- <table border="1">
    @foreach ($projects as $pro)
    <tr>
        <td><a href="{{ url("/project/{$pro->id}") }}">{{ $pro->name }}</a></td>
    </tr>
    @endforeach
</table> --}}

<head>
    <link rel="stylesheet" href="/vendor/laravel-admin/font-awesome/css/font-awesome.min.css">
</head>

<style>  
    .project {  
        border: 1px solid black;  
        margin-bottom: 10px; /* 项目之间的间距 */  
    }  
    .project-name {  
        background-color: #f2f2f2;  
        padding: 5px;  
    }  
    .modules {  
        display: flex;  
        flex-wrap: wrap; /* 允许模块换行 */  
    }  
    .module {  
        flex: 0 0 20%; /* 每个模块占据20%的宽度，你可以根据需要调整 */  
        max-width: 20%; /* 防止模块宽度超过设定值 */  
        border: 1px solid #ccc;  
        padding: 5px;  
        box-sizing: border-box; /* 包含边框和内边距在宽度内 */  
    }
    .juti {  
        font-size: 80%; /* 每个模块占据20%的宽度，你可以根据需要调整 */  
    }
    .right-button {
        float: right;  
        clear: both; /* 清除浮动，避免影响其他元素 */
    }
    a {  
        text-decoration: none; /* 移除下划线 */  
        background-color: transparent; /* 确保没有背景色造成的高亮效果 */  
        color: inherit; /* 如果需要的话，让链接颜色继承父元素的颜色 */  
        outline: none; /* 移除点击时可能出现的轮廓线 */  
    }  

    .text-with-line {  
        display: inline-block; /* 使得文本元素表现为行内块级元素 */  
        border-bottom: 1px solid #000; /* 添加底部横线 */  
        margin-bottom: 5px; /* 可选：为横线下方添加一些间距 */  
        border: 1px solid #000; /* 添加边框，1像素宽，实线，黑色 */  
        /* 设置底色为浅灰色 */  
        padding: 10px; /* 可选：为边框内部添加一些内边距 */
    } 
    .icon-demand, .icon-prototype {  
        display: none; /* 初始状态隐藏图标 */  
        margin-left: 5px; /* 图标与文本之间的间距 */  
        font-family: 'Font Awesome 5 Free'; /* 使用Font Awesome字体 */  
        font-weight: 900; /* 确保图标正确显示 */  
    }  
    
    .icon-demand::before {  
        content: "\f067"; /* Font Awesome中“需求”图标的Unicode */  
    }  
    
    .icon-prototype::before {  
        content: "\f1eb"; /* Font Awesome中“原型”图标的Unicode */  
    }  
    
    .visible {  
        display: inline-block; /* 当需要显示图标时 */  
    }

    .progress-bar {  
        height: 20px;  
        background-color: #ddd;  
        border-radius: 5px;  
        overflow: hidden;  
    }  
    .progress-bar-fill {  
        height: 100%;  
        background-color: #4CAF50; /* 您可以根据需要更改这个颜色 */  
        text-align: right;  
        color: white;  
        line-height: 20px; /* 使文本垂直居中 */  
        white-space: nowrap; /* 防止文本换行 */  
    }  
    #gongzuojilu {  
            display: none;   
        } 
    #jihua {  
        display: none;   
    } 
    @foreach ($admin_users_busy as $admin_user) 

        #tixingform{{ $admin_user->id }} {  
            display: none;  
        } 
    @endforeach
    .bubble { 
        cursor:pointer; 
        display: inline-block;  
        padding: 2px 5px;  
        border-radius: 50%;  
        background-color: #ff0000; /* 你可以根据需要修改这个颜色 */  
        color: white;  
        font-size: 12px;  
        margin-left: 5px; /* 根据需要调整 */  
        vertical-align: top; /* 根据需要调整垂直对齐 */  
    }
</style>
<div class="projects" id="jihua">        
    <div class="project">    
        <div class="project-name">    
            <b>工作计划</b>
            <span>
                <button onclick="hideDivPlan()">隐藏工作计划</button>
            </span>
        </div>   
        <div class="modules">    
                
                @foreach ($grouped_plans as $date=>$plans)    
                <div class="module">    
                   <b> {{ $date }}</b>
                   <div class="juti">
                   <br/>
                    @foreach ($plans as $k=>$plans_persons)
                    @foreach ($plans_persons as $plans_person)
                        <div class='text-with-line'>
                            {{ 
                                
                                $k."：".$plans_person->adminUserRequirement->requirement->module->project->name.'-'.
                                $plans_person->adminUserRequirement->requirement->module->name.'-'.
                                $plans_person->adminUserRequirement->requirement->type.'-'.
                                $plans_person->adminUserRequirement->requirement->name.'-'.$plans_person->adminUserRequirement->type.
                            '('.$plans_person->adminUserRequirement->status.')'; }}
                            <br> 
                            {{ '预计耗时：'; }}<b>{{ $plans_person->times.'小时'; }} </b> {{ '   '; }}
                            <br>
                            {{ '工作内容描述：'.(isset($plans_person->description)?$plans_person->description:'未记录'); }}

                        </div>    
                            <br/>
                            @endforeach
                            
                    @endforeach
                    <br>
                    </div>
                </div>
                
                @if ($loop->iteration % 5 == 0 && $loop->iteration != count($admin_users_busy))    
                    <div style="width: 100%;"></div>    
                @endif    
                @endforeach    
  
        </div>


    </div>       
</div> 
<div class="projects" id="gongzuojilu">        
    <div class="project">    
        <div class="project-name">    
            <b>工作日志</b>
            <span>
                <button onclick="hideDiv()">隐藏工作日志</button>
            </span>
        </div>   
        <div class="modules">    
                
                @foreach ($grouped_logs as $date=>$logs)    
                <div class="module">    
                   <b> {{ $date }}</b>
                   <div class="juti">
                   <br/>
                    @foreach ($logs as $k=>$logs_persons)
                    @foreach ($logs_persons as $logs_person)
                        <div class='text-with-line'>
                            {{ 
                                
                                $k."：".$logs_person->adminUserRequirement->requirement->module->project->name.'-'.
                                $logs_person->adminUserRequirement->requirement->module->name.'-'.
                                $logs_person->adminUserRequirement->requirement->type.'-'.
                                $logs_person->adminUserRequirement->requirement->name.'-'.$logs_person->adminUserRequirement->type.
                            '('.$logs_person->adminUserRequirement->status.')'; }}
                            <br> 
                            {{ '耗时：'; }}<b>{{ $logs_person->times.'小时'; }} </b> {{ '   '; }}
                            {{ '预计交付状态：'.(isset($logs_person->give_status)?$logs_person->give_status:'未记录'); }}
                            <br>
                            {{ '工作内容描述：'.(isset($logs_person->description)?$logs_person->description:'未记录'); }}

                        </div>    
                            <br/>
                            @endforeach
                            
                    @endforeach
                    <br>
                    </div>
                </div>
                
                @if ($loop->iteration % 5 == 0 && $loop->iteration != count($admin_users_busy))    
                    <div style="width: 100%;"></div>    
                @endif    
                @endforeach    
  
        </div>


    </div>       
</div> 
<div class="projects">        
    <div class="project">    
        <div class="project-name">    
            <b>任务看板</b>
            <span>
                <a href="/admin"><button>进入后台</button></a>
            </span>
            <span>
                <a href="/admin/logs"><button>日志上报</button></a>
            </span>
            <span>
                <button onclick="showDiv()">显示工作日志</button>
            </span>
            <span>
                <a href="/admin/plans"><button>计划上报</button></a>
            </span>
            <span>
                <button onclick="showDivPlan()">显示工作计划</button>
            </span>
            <span style="float:right;">
            @foreach($colors as $color)
                <span style="border: 1px solid #000;background-color:{{ $color->color }};">_</span>{{ $color->name }}
            @endforeach 
            <i class="fa fa-book"></i>需求
            <i class="fa fa-file-image-o"></i>原型图
            </span>
        </div>
        <b>BUSY</b>    
        <div class="modules">    
                
                @foreach ($admin_users_busy as $admin_user)    
                <div class="module">    
                   {{-- <a href="/admin_user/{{ $admin_user->id }}" target="_blank"><b> {{ $module->name }}</b></a> --}}
                   <b> {{ $admin_user->name }}</b>
                   @if ($admin_user->pending_reminds_count > 0)  
                        <span class="bubble" data-id="{{ $admin_user->id }}">{{ $admin_user->pending_reminds_count }}</span>  
                    @endif 
                   <div id="tixingform{{ $admin_user->id }}">
                        <form method="POST" action="/api/store_remind">
                        <input name="content" placeholder="提醒内容" type="text" required>
                        <input name="remind_admin_user_id" value="{{ $admin_user->id }}" style="display: none;">
                        <input name="now_admin_user_id" value="{{ $now_admin_user_id }}" style="display: none;">
                        <select name="admin_user_requirement_id"  placeholder="提醒任务"  required>
                            <option value="">请选择</option>
                        @foreach ($admin_user->adminUserRequirements as $adminUserRequirement)
                            @if($adminUserRequirement->status=="未开始" ||$adminUserRequirement->status=="进行中" ||$adminUserRequirement->status=="停滞")

                                <option value="{{ $adminUserRequirement->id }}">
                                    {{ $adminUserRequirement->requirement->module->project->name.'-'.
                                            $adminUserRequirement->requirement->module->name.'-'.
                                            $adminUserRequirement->requirement->type.'-'.
                                            $adminUserRequirement->requirement->name }}
                                </option>    
                            @endif
                        @endforeach
                        </select>
                        <input type="submit" value="提交">
                        </form> 
                   </div>
                   <div id="tixingbutton{{ $admin_user->id }}" style="float:right;">
                        <button class="reminder-button" data-id="{{ $admin_user->id }}">提醒</button>
                   </div>
                   <div class="juti">
                    <div id="work-log-container{{ $admin_user->id }}"></div>
                   <br/>
                        @if ($admin_user->adminUserRequirements)
                            @foreach ($admin_user->adminUserRequirements as $adminUserRequirement)
                                    @if($adminUserRequirement->status=="未开始" ||$adminUserRequirement->status=="进行中" ||$adminUserRequirement->status=="停滞")
                                <div class='text-with-line' style="background-color:{{ empty($adminUserRequirement->requirement->orderColor->color)?'':$adminUserRequirement->requirement->orderColor->color }};">
                                    <a target="_blank" href="/admin/admin_user_requirement/{{ $adminUserRequirement->id }}/edit">{{ $adminUserRequirement->requirement->module->project->name.'-'.
                                            $adminUserRequirement->requirement->module->name.'-'.
                                            $adminUserRequirement->requirement->type.'-'.
                                            $adminUserRequirement->requirement->name.'-'.$adminUserRequirement->type.
                                            '('.$adminUserRequirement->status.')';
                                            }}

                                    @if(!empty($adminUserRequirement->requirement->content))<i class="fa fa-book"></i>@endif
                                    @if(!empty($adminUserRequirement->requirement->prototype_path))<i class="fa fa-file-image-o"></i>@endif
                                    </a>
                                    @if(!empty($adminUserRequirement->persentage) && $adminUserRequirement->persentage>0)
                                    <div class="progress-bar" style="width: {{ $adminUserRequirement->persentage }}%;">  
                                        <div class="progress-bar-fill" style="width: 100%;">{{ $adminUserRequirement->persentage }}%</div>  
                                    </div>
                                    @endif  
                                </div>    
                                    <br/>

                                    @endif
                            @endforeach
                        @endif
                    <br>
                    </div>
                </div>
                
                @if ($loop->iteration % 5 == 0 && $loop->iteration != count($admin_users_busy))    
                    <div style="width: 100%;"></div>    
                @endif    
                @endforeach    
  
        </div>
        <b>FREE</b>    
        <div class="modules">    
                
            @foreach ($admin_users_free as $admin_user)    
            <div class="module">    
               {{-- <a href="/admin_user/{{ $admin_user->id }}" target="_blank"><b> {{ $module->name }}</b></a> --}}
               <b> {{ $admin_user->name }}</b>
            </div>
            <br/>
            @if ($loop->iteration % 5 == 0 && $loop->iteration != count($admin_users_free))    
                <div style="width: 100%;"></div>    
            @endif    
            @endforeach    
    </div>
    </div>       
</div>  
<div class="projects">        
    <div class="project">    
        <div class="project-name">    
            <b>需求看板</b>
        </div>
        <div class="modules">     
                @foreach ($requirements as $requirement)
                    @if ($requirement['name']=='停滞')
                        <div class="module" style="flex: 0 0 40%;max-width: 40%;"> 
                            <b>停滞</b><br/> 
                            <div class="juti">
                            @if (!empty($requirement_tingzhi))
                            @foreach ($requirement_tingzhi as $adminUserRequirement) 
                                <div class='text-with-line' style="background-color:{{ empty($adminUserRequirement->requirement->orderColor->color)?'':$adminUserRequirement->requirement->orderColor->color }};">
                                    <a target="_blank" href="/admin/admin_user_requirement/{{ $adminUserRequirement->id }}/edit">{{ $adminUserRequirement->requirement->module->project->name.'-'.
                                    $adminUserRequirement->requirement->module->name.'-'.
                                    $adminUserRequirement->requirement->type.'-'.
                                    $adminUserRequirement->requirement->name.'-'.$adminUserRequirement->type.
                                    '('.$adminUserRequirement->adminUser->name.')'
                                    }}
                                        @if(!empty($adminUserRequirement->requirement->content))<i class="fa fa-book"></i>@endif
                                        @if(!empty($adminUserRequirement->requirement->prototype_path))<i class="fa fa-file-image-o"></i>@endif    
                                    </a>
                                    @if(!empty($adminUserRequirement->persentage) && $adminUserRequirement->persentage>0)
                                    <div class="progress-bar" style="width: {{ $adminUserRequirement->persentage }}%;">  
                                        <div class="progress-bar-fill" style="width: 100%;">{{ $adminUserRequirement->persentage }}%</div>  
                                    </div>
                                    @endif 
                                </div>
                                <br/>       
                            @endforeach
                            @endif
                            </div>
                        </div> 
                    @else
                        <div class="module"> 
                            <b> {{ $requirement['name'] }}</b><br/> 
                            <div class="juti">
                            @if (!empty($requirement['data']))
                            @foreach ($requirement['data'] as $data) 
                            <div class='text-with-line'  style="background-color:{{ empty($data->orderColor->color)?'':$data->orderColor->color }};">
                                <a target="_blank" href="/admin/requirements/{{ $data->id }}">{{ $data->module->project->name.'-'.$data->module->name.'-'.$data->type.'-'.$data->name }}
                                    @if(!empty($data->content))<i class="fa fa-book"></i>@endif
                                    @if(!empty($data->prototype_path))<i class="fa fa-file-image-o"></i>@endif    
                                    <br/>
                                @if (!empty($data->adminUserRequirements))
                                    (
                                
                                    @foreach ($data->adminUserRequirements as $k=>$adminUserRequirement) 
                                            @if ($k!=0)
                                                、
                                            @endif
                                            
                                            @if($adminUserRequirement->status=="已完成" || $adminUserRequirement->status=="已归档" )
                                                <span><del>{{ $adminUserRequirement->adminUser->name.'_'.$adminUserRequirement->type }}</del></span>
                                            @else
                                                <span>{{ $adminUserRequirement->adminUser->name.'_'.$adminUserRequirement->type }}</span>
                                            @endif
                                    @endforeach
                                    )

                                    </a>
                                @endif
                                <br>
                            </div>        
                            @endforeach
                            @endif
                            </div>
                        </div>
                    @endif    
                    
                    
                    @if ($loop->iteration % 5 == 0 && $loop->iteration != count($requirements))    
                        <div style="width: 100%;"></div>    
                    @endif    
                    @endforeach
                   
  
        </div>    
    </div>       
</div>
{{-- 快捷入口面板 --}}
<div class="projects">    
    @foreach ($projects as $pro)    
    <div class="project">    
        <div class="project-name">    
            {{-- <a href="{{ url("/project/{$pro->id}") }}"><b>{{ $pro->name }}</b></a>     --}}
            <b>{{ $pro->name }}</b>   
        </div>    
        <div class="modules">    
            @if ($pro->modules)    
                @foreach ($pro->modules as $module)    
                <div class="module">    
                   <a href="/module/{{ $module->id }}" target="_blank"><b> {{ $module->name }}</b></a>
                        <p class="right-button">
                        @if ($module->test)  
                            <a href="{{ $module->test }}" target="_blank"><button class="access-button" data-toggle="modal" data-target="#accessModal">测试</button></a>  
                        @endif
                        @if ($module->yanshi)
                            <a href="{{ $module->yanshi }}" target="_blank"><button class="access-button" data-toggle="modal" data-target="#accessModal">演示</button></a>  
                        @endif
                        @if ($module->product)
                            <a href="{{ $module->product }}" target="_blank"><button class="access-button" data-toggle="modal" data-target="#accessModal">生产</button></a>  
                        @endif
                        </p>
                    <br>
                    {{-- <p>紧急需求</p> --}}
                </div>
                
                @if ($loop->iteration % 5 == 0 && $loop->iteration != count($pro->modules))    
                    <div style="width: 100%;"></div>    
                @endif    
                @endforeach    
            @else    
                <div class="module">没有模块</div>    
            @endif    
        </div>    
    </div>    
    @endforeach    
</div>  

<script>
function showDiv() {  
    var div = document.getElementById("gongzuojilu");  
    div.style.display = "block";  
}  
  
function hideDiv() {  
    var div = document.getElementById("gongzuojilu");  
    div.style.display = "none";  
}
function showDivPlan() {  
    var div = document.getElementById("jihua");  
    div.style.display = "block";  
}  
  
function hideDivPlan() {  
    var div = document.getElementById("jihua");  
    div.style.display = "none";  
}

/* @foreach ($admin_users_busy as $admin_user) 
    function showDiv{{ $admin_user->id }}() 
    {  
        alert({{ $admin_user->id }})
        var div = document.getElementById("tixingform{{ $admin_user->id }}");  
        div.style.display = "block";
        var div2 = document.getElementById("tixingbutton{{ $admin_user->id }}");  
        div2.style.display = "none";
    }
@endforeach */
</script>

<script>  
    document.addEventListener('DOMContentLoaded', function() {  
        // 获取所有的提醒按钮  
        var buttons = document.querySelectorAll('.reminder-button');  
        buttons.forEach(function(button) {  
            // 为每个按钮添加点击事件监听器  
            button.addEventListener('click', function() {  
                var userId = this.getAttribute('data-id'); // 获取用户ID    
                var div = document.getElementById("tixingform" + userId);  
                div.style.display = "block";  
                var div2 = document.getElementById("tixingbutton" + userId);  
                div2.style.display = "none";  
            });  
        });  
    });  
</script>

<script>
    // 注入提醒列表
document.addEventListener('DOMContentLoaded', function() {  
    const bubbles = document.querySelectorAll('.bubble');  
    bubbles.forEach(function(bubble) {  
        bubble.addEventListener('click', function() {  
            const adminUserId = this.getAttribute('data-id');  
            showWorkLog(adminUserId);  
        });  
    });  
});
function showWorkLog(adminUserId) {  
    // 发送 AJAX 请求获取数据  
    fetch(`/api/get-work-log/${adminUserId}`)  
        .then(response => response.json())  
        .then(responseData => { // 注意这里我们重命名了变量以避免混淆  
            const workLogContainer = document.getElementById('work-log-container'+responseData.remind_admin_user_id);  
            workLogContainer.innerHTML = '';  
  
            // 假设后端只返回了一个字符串，我们直接将其放入一个 <p> 标签内  
            let workLogHtml = `${responseData.data}`; // 使用 responseData.data 来获取字符串  
            workLogContainer.innerHTML = workLogHtml; // 将 HTML 内容添加到容器中  
        })   
        .catch(error => {  
            console.error('Error fetching work log:', error);  
        });  
}
</script>

<script>
    @foreach ($admin_users_busy as $admin_user) 
        document.addEventListener('DOMContentLoaded', function() {  
            // 绑定事件委托到静态父元素上  
            document.getElementById('work-log-container'+{{ $admin_user->id }}).addEventListener('click', function(event) {  
                // 检查被点击的元素是否是我们关心的按钮  
                var target = event.target;  
                if (target.matches('.received-button')) {  
                    // 获取 data-reminder-id 属性  
                    var reminderId = target.getAttribute('data-reminder-id');  
                    // 调用函数处理点击事件  
                    markReminderAsReceived(reminderId);  
                }  
            });  
        });  
  @endforeach
function markReminderAsReceived(reminderId) {  
    fetch(`/api/mark-reminder-as-received/${reminderId}`, {  
        method: 'POST'  
    })  
    .then(response => {  
        if (!response.ok) {  
            throw new Error('Network response was not ok.');  
        }  
        return response.json(); // 解析响应体为JSON  
    })  
    .then(data => {  
        if (data.status === 'ok') {  
            var div2 = document.getElementById("reply_remind" + reminderId);  
            if (div2) {  
                div2.style.display = "none";  
            } else {  
                console.warn(`Element with ID "replay_remind${reminderId}" not found.`);  
            }  
        } else {  
            // 处理错误情况  
            console.error('Error marking reminder as received:', data.error);  
        }  
    })  
    .catch(error => {  
        console.error('Error marking reminder as received:', error);  
    });  
}
</script>